package cn.lh.sys.service.impl;

import cn.lh.basic.service.impl.BaseServiceImpl;
import cn.lh.sys.domain.DictionaryType;
import cn.lh.sys.mapper.DictionaryDetailMapper;
import cn.lh.sys.mapper.DictionaryTypeMapper;
import cn.lh.sys.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class DictionaryTypeServiceImpl extends BaseServiceImpl<DictionaryType> implements IDictionaryTypeService {

    @Autowired
    private DictionaryTypeMapper dictionaryTypeMapper;

    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;

    @Override
    @Transactional
    public void batchDelete(Long[] ids) {
//        Integer count = dictionaryDetailMapper.countByTypeIds(ids);
//        Integer updateCount = dictionaryDetailMapper.batchDeleteByTypeIds(ids);
//        if (count.equals(updateCount)){
//            dictionaryTypeMapper.batchDelete(ids);
//        }
        dictionaryDetailMapper.batchDeleteByTypeIds(ids);
        dictionaryTypeMapper.batchDelete(ids);
    }

    @Override
    @Transactional
    public void del(Long id) {
//        Integer count = dictionaryDetailMapper.countByTypeId(id);
//        Integer updateCount = dictionaryDetailMapper.deleteByTypeId(id);
//        if (count.equals(updateCount)){
//            dictionaryTypeMapper.remove(id);
//        }
        dictionaryDetailMapper.deleteByTypeId(id);
        dictionaryTypeMapper.remove(id);
    }
}
